import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GCAnalyzer {

	public static void main(String[] args) throws FileNotFoundException {
		Scanner fileScanner = new Scanner(new File("gc.log"));

		System.out.println("TS\tdTS\tRq[K]\tYb\tYa\tFb\tFa\tC\tP\tPS[ms]");

		float oldTimestamp = 0;

		float requestRate = Float.parseFloat(fileScanner.nextLine());

		while (fileScanner.hasNextLine()) {

			String line = fileScanner.nextLine();

			// 5.042: [GC5.042: [ParNew: 4416K->512K(4928K), 0.0028600 secs]
			// 4416K->689K(15872K), 0.0030096 secs] [Times: user=0.00 sys=0.00,
			// real=0.00 secs]

			Pattern pattern = Pattern
					.compile("((\\d+\\.\\d+):.*?ParNew: (\\d+)K->(\\d+)K.*?(\\d+)K->(\\d+)K.*?, (\\d+\\.\\d+) secs)");

			Matcher matcher = pattern.matcher(line);
			if (matcher.find()) {
				// System.out.println(matcher.group(1));
				// System.out.println(matcher.group(2));
				// System.out.println(matcher.group(3));
				// System.out.println(matcher.group(4));
				// System.out.println(matcher.group(5));

				float timestamp = Float.parseFloat(matcher.group(2));
				float deltaTimestamp = cut(timestamp - oldTimestamp, 3);
				oldTimestamp = timestamp;
				int youngBefore = Integer.parseInt(matcher.group(3));
				int youngAfter = Integer.parseInt(matcher.group(4));
				int fullBefore = Integer.parseInt(matcher.group(5));
				int fullAfter = Integer.parseInt(matcher.group(6));
				float pause = cut(Float.parseFloat(matcher.group(7)) * 1000, 3);

				int collected = fullBefore - fullAfter;
				int promoted = youngBefore - youngAfter - collected;

				System.out.println(timestamp + "\t" + deltaTimestamp + "\t"
						+ cut(requestRate * deltaTimestamp / 1000, 2) + "\t"
						+ youngBefore + "\t" + youngAfter + "\t" + fullBefore
						+ "\t" + fullAfter + "\t" + collected + "\t" + promoted
						+ "\t" + pause);
			}
		}
	}

	private static float cut(float number, int digits) {
		double mult = Math.pow(10, digits);

		return (float) ((float) Math.round(number * mult) / mult);
	}
}
